# !usr/bin/env python
# -*- coding:utf-8 _*-
"""
@Author:张广勤
@Web site: https://www.tunan.wang
@Github:www.github.com
 
@File:chrome_test7_0.py
@Time:2024/11/3 15:37

@Motto:不积跬步无以至千里，不积小流无以成江海！
"""
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from time import sleep

# 指定 ChromeDriver 的路径
driver_path = 'd:/code_zgq/ganbu/chromedriver.exe'
service = Service(executable_path=driver_path)

# 创建 WebDriver 实例
driver = webdriver.Chrome(service=service)
driver.implicitly_wait(5)
driver.maximize_window()

# 打开网页
driver.get('https://www.sxgbxx.gov.cn/login')


# 找到用户名输入框并输入用户名
driver.find_element(By.ID, 'userEmail').send_keys('u0122092')


# 找到密码输入框并输入密码
driver.find_element(By.ID, 'userPassword').send_keys('071726zgq001!')


# 提示用户输入验证码
input("按回车继续...")

# 专题 首页-好干部在线-山西干部在线学院
# //*[@id="aCoursesList"]/div[1]/div[3]/div[2]/ul/li[1]/div/a/div/img
#                                    #aCoursesList > div.container > div.mt30.m-top-box.tzc_zt_dbox > div.net-cou-box > ul > li:nth-child(1) > div > a > div > img
driver.find_element(By.CSS_SELECTOR,"#aCoursesList > div.container > div.mt30.m-top-box.tzc_zt_dbox > div.net-cou-box > ul > li:nth-child(1) > div > a > div > img").click()
print(driver.title)
sleep(3)
all_handles = driver.window_handles
driver.switch_to.window(all_handles[-1])
# driver.get(driver.current_url)
# 立即学习
# 党的二十届三中全会精神网络培训专题-好干部在线-山西干部有线学院
# //*[@id="aCoursesList"]/div/div[1]/article[2]/div/div[4]/div/a
#                                    #aCoursesList > div > div.i-box.clearfix.pr.of.mt20.m-video-box > article.fl.c-a-wrap.cou-a-wrap > div > div.mt20.clearfix.of > div > a
driver.find_element(By.CSS_SELECTOR,"#aCoursesList > div > div.i-box.clearfix.pr.of.mt20.m-video-box > article.fl.c-a-wrap.cou-a-wrap > div > div.mt20.clearfix.of > div > a").click()
sleep(3)
print(driver.title)

# 计划详情-好干部在线-山西干部在线学院
# 继续学习
all_handles = driver.window_handles
driver.switch_to.window(all_handles[0])
driver.get(driver.current_url)
# driver.current_window_handle
# /html/body/div[1]/div[1]/div[4]/section[2]/div/div/article/div[2]/section/div[1]/div/div[2]/ul/li[1]/aside/a
#                                    body > div.in-wrap > div.nxb-box.ucenter-box > div.bg-fa.of > section.container > div > div > article > div.i-box.mt20 > section > div.p-l-wrap > div > div.p-cou-wrap.p-l-module > ul > li:nth-child(1) > aside > a
#                                    body > div.in-wrap > div.nxb-box.ucenter-box > div.bg-fa.of > section.container > div > div > article > div.i-box.mt20 > section > div.p-l-wrap > div > div.p-cou-wrap.p-l-module > ul > li:nth-child(1) > aside > a
# driver.get("https://www.sxgbxx.gov.cn/front/couinfo/870a4f1201e8d51e")
# driver.get("https://www.sxgbxx.gov.cn/front/playkpoint/870a4f1201e8d51e")
driver.find_element(By.CSS_SELECTOR,"body > div.in-wrap > div.nxb-box.ucenter-box > div.bg-fa.of > section.container > div > div > article > div.i-box.mt20 > section > div.p-l-wrap > div > div.p-cou-wrap.p-l-module > ul > li:nth-child(1) > aside > a").click()
sleep(3)
# driver.switch_to.window(all_handles[-1])
all_handles = driver.window_handles
driver.switch_to.window(all_handles[-1])
driver.get(driver.current_url)
print(driver.title)



# 学习贯彻党的二十届三中全会精神-好干部在线-山西干部在线学院
# //*[@id="aCoursesList"]/div/div[1]/article[2]/div/div[4]/div/a
# #aCoursesList > div > div.i-box.clearfix.pr.of.mt20.m-video-box > article.fl.c-a-wrap.cou-a-wrap > div > div.mt20.clearfix.of > div > a
driver.find_element(By.CSS_SELECTOR,"#aCoursesList > div > div.i-box.clearfix.pr.of.mt20.m-video-box > article.fl.c-a-wrap.cou-a-wrap > div > div.mt20.clearfix.of > div > a").click()
print(driver.title)
sleep(3)

# driver.get("https://www.sxgbxx.gov.cn/front/playkpoint/870a4f1201e8d51e")
# # //*[@id="kp_2"]
# print(driver.title)
# element = driver.find_element(By.XPATH,'//*[@id="kp_1"]')
# a_tag = element.find_element(By.XPATH,"./div/a[2]")
# if a_tag.get_attribute("title")=='图文播放':
#     sleep(10)
#     print(a_tag.get_attribute("title"))
#     print(a_tag.text)
# # //*[@id="kp_1"]/div/a[1]/span
# # //*[@id="kp_1"]/div/a[2]
# #
# element = driver.find_element(By.XPATH,'//*[@id="kp_2"]')
# a_tag = element.find_element(By.XPATH,"./div/a[2]")
# if a_tag.get_attribute("title")=='视频播放':
#     a_tag.click()
#     print(a_tag.get_attribute("title"))
#     # play = driver.find_element(By.CSS_SELECTOR, "div.pv-cover > span")
#     # play.click()
#     play = driver.find_element(By.XPATH,'//*[@id="video_box"]/div/div[1]/div[5]/span').click()
#     print('播放视频》》》》》》》》》》')
#     sleep(20)


# print(element)
# print(element.text)




print("到了")
driver.quit()
